// components/base/row/row.js
const { BaseBehavior, COMPONENT_OPTIONS } = require('../../mixins/component');
Component({
    behaviors: [BaseBehavior],
    options: {
        ...COMPONENT_OPTIONS,
    },
    properties: {
        gutter: {
            type: Number,
            observer: 'setGutter'
        }
    },
    relations: {
        '../col/index': {
            type: 'descendant',
            linked: function(target) {
                // 每次被插入到custom-ul时执行，target是custom-ul节点实例对象，触发在attached生命周期之后
                if (this.data.gutter) {
                    target.setGutter(this.data.gutter);
                }
            },
        },
    },
    data: {
        viewStyle: '',
    },
    methods: {
        setGutter: function () {
            var _this = this;
            var gutter = this.data.gutter;
            var margin = "-" + Number(gutter) / 2 + "px";
            var viewStyle = gutter
                ? "margin-right: " + margin + "; margin-left: " + margin + ";"
                : '';
            this.setData({ viewStyle: viewStyle });
            this.getRelationNodes('../col/index').forEach(function (col) {
                col.setGutter(_this.data.gutter);
            });
        }
    }
})
